local thbattle__bayiyonglin_yuexian = fk.CreateSkill {

  name = "thbattle__bayiyonglin_yuexian",

  tags = {},

}



thbattle__bayiyonglin_yuexian:addEffect("viewas", {
  name="thbattle__bayiyonglin_yuexian",
  prompt = "#thbattle__bayiyonglin_yuexian",
  pattern = "danmu__slash",
  anim_type = "offensive",
  view_as = function(self, player, cards)
    if #cards ~= 1 then
      return
    end
    local c = Fk:cloneCard("danmu__slash")
    c.skillName = thbattle__bayiyonglin_yuexian.name
    self.cost_data=cards
    return c
  end,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and table.contains(player:getCardIds("h"), to_select)
  end,
  before_use = function(self, player, use)
    local room = player.room
    local choice = room:askForChoice(player, { "Top", "Bottom" }, thbattle__bayiyonglin_yuexian.name,
      "#thbattle__bayiyonglin_yuexian-choice")
    local targetCard=self.cost_data
    if choice == "Top" then
      room:moveCards({
        ids = targetCard,
        from = player,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        proposer = player,
        moveVisible = true,
      })
    else
      room:moveCards({
        ids = targetCard,
        from = player,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        proposer = player,
        moveVisible = true,
        drawPilePosition = -1,
      })
    end
  end,
  enabled_at_play = function(self, player)
    return self:withinTimesLimit(player, Player.HistoryPhase)
  end,
})

return thbattle__bayiyonglin_yuexian
